package com.alatus.manager;


import com.alatus.mapper.TActivityMapper;
import com.alatus.mapper.TClueMapper;
import com.alatus.mapper.TCustomerMapper;
import com.alatus.mapper.TTranMapper;
import com.alatus.result.ChartData;
import com.alatus.result.SummaryData;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class StatisticManager {
    @Resource
    private TActivityMapper tActivityMapper;
    @Resource
    private TClueMapper tClueMapper;
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TTranMapper tTranMapper;
    public SummaryData loadSummaryData() {
        //有效的市场活动总数
        Integer effectiveActivityCount = tActivityMapper.selectOnGoingActivities().size();

        //总的市场活动数
        Integer totalActivityCount = tActivityMapper.selectActivityCount();

        //线索总数
        Integer totalClueCount = tClueMapper.selectClueCount();

        //客户总数
        Integer totalCustomerCount = tCustomerMapper.selectCustomerCount();

        //成功的交易额
        BigDecimal successTranAmount = tTranMapper.selectTranSuccessAmount();

        //总的交易额（包含成功和不成功的）
        BigDecimal totalTranAmount = tTranMapper.selectAllTranAmount();
        return SummaryData.builder()
                .effectiveActivityCount(effectiveActivityCount)
                .totalActivityCount(totalActivityCount)
                .totalClueCount(totalClueCount)
                .totalCustomerCount(totalCustomerCount)
                .successTranAmount(successTranAmount)
                .totalTranAmount(totalTranAmount)
                .build();
    }

    public List<ChartData> loadSaleFunnel() {
        List<ChartData> saleFunnel = new ArrayList<>();
//        多少个线索
        Integer clueCount = tClueMapper.selectClueCount();
//        多少个顾客
        Integer totalCustomerCount = tCustomerMapper.selectCustomerCount();
//        多少个成交
        Integer TranAmount = tTranMapper.selectTranAmount();
//        多少个成功交易
        Integer TranSuccessAmount = tTranMapper.selectTranSuccessNum();
        ChartData clue = ChartData.builder().name("线索").value(clueCount).build();
        saleFunnel.add(clue);
        ChartData customer = ChartData.builder().name("客户").value(totalCustomerCount).build();
        saleFunnel.add(customer);
        ChartData tran = ChartData.builder().name("交易").value(TranAmount).build();
        saleFunnel.add(tran);
        ChartData successTran = ChartData.builder().name("成交").value(TranSuccessAmount).build();
        saleFunnel.add(successTran);
        return saleFunnel;
    }

    public List<ChartData> loadSourcePie() {
        List<ChartData> chartData = tClueMapper.selectBySource();
        return chartData;
    }
}
